
public class QuickSort {
    private static void printArray(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
    //快速排序
   public static void quickSort(int[] arr, int start, int end){
       if(end<=start){
           return;
       }
       int low=start;
       int high=end;
       int pivot=arr[low];//基准元素
       while (low<high){
           while (low<high && arr[high]>=pivot){
               high--;
           }
           arr[low]=arr[high];
           while (low<high && arr[low] <= pivot){
               low++;
           }
           arr[high]=arr[low];
           }
       arr[low]=pivot;
       quickSort(arr,start,low-1);
       quickSort(arr,low+1,end);
       }
    public static void main(String[] args) {
        int[] arr=new int[]{45,37,63,91,26,13,58,2};
        quickSort(arr,0,arr.length-1);
        printArray(arr);

    }

}
   

